package com.letu.core.context;

import cn.hutool.core.convert.Convert;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
 * 全局变量
 *
 * @author ligang
 * @date 2017-12-13 16:52
 */
public final class StaticContextUtil {
    private StaticContextUtil() {
    }

    private static final Map<String, Object> STATIC_LOCAL = new ConcurrentHashMap<>();

    public static void set(String key, Object value) {
        STATIC_LOCAL.put(key, value);
    }

    public static <T> T get(String key, Class<T> type) {
        return Convert.convert(type, STATIC_LOCAL.get(key));
    }


    /**
     * IP地址
     */
    public static String getIpAddr() {
        return get(ContextConstants.IPADDR, String.class);

    }

    public static void setIpAddr(String val) {
        set(ContextConstants.IPADDR, val);
    }


    /**
     * 当前环境
     */
    public static String getProfilesActive() {
        return get(ContextConstants.PROFILE_ACTIVE, String.class);

    }

    public static void setProfilesActive(String val) {
        set(ContextConstants.PROFILE_ACTIVE, val);
    }


    /**
     * 服务重启时间
     */
    public static Long getReLoadTime() {
        return get(ContextConstants.RELOAD_TIME, Long.class);
    }

    public static void setReLoadTime(Long t) {
        set(ContextConstants.RELOAD_TIME, t);
    }


    /**
     * 租户规则信息
     */
    public static String getTenantRule() {
        return get(ContextConstants.TENANT_RULE, String.class);
    }

    public static void setTenantRule(String t) {
        set(ContextConstants.TENANT_RULE, t);
    }



    public static void setStaticProjectWorkId(String val) {
        set(ContextConstants.STATIC_PROJECT_WORK_ID, val);
    }

    public static String getStaticProjectWorkId() {
        return get(ContextConstants.STATIC_PROJECT_WORK_ID, String.class);
    }

}
